from typing import Optional, List, Any
from pydantic import BaseModel
from datetime import datetime


class ProductBase(BaseModel):
    product_title: str
    product_tags: Optional[str] = None
    product_description: Optional[str] = None
    image_url: str
    image_width: Optional[int] = None
    image_height: Optional[int] = None
    # 新增：腾讯图库 EntityId
    entity_id: Optional[str] = None
    cos_url: Optional[str] = None
    cos_key: Optional[str] = None
    source_type: str
    source_index: Optional[int] = None
    detail_content: Optional[str] = None


class ProductCreate(ProductBase):
    workflow_id: int
    user_id: int


class ProductUpdate(BaseModel):
    product_title: Optional[str] = None
    product_tags: Optional[str] = None
    product_description: Optional[str] = None
    image_width: Optional[int] = None
    image_height: Optional[int] = None
    cos_url: Optional[str] = None
    cos_key: Optional[str] = None
    detail_content: Optional[str] = None


class ProductResponse(ProductBase):
    id: int
    workflow_id: Optional[int] = None
    user_id: int
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True


class ProductListResponse(BaseModel):
    code: int = 200
    msg: str = "成功"
    data: List[ProductResponse]
    total: int